package com.ai.trickycards

import android.app.Application
import androidx.lifecycle.HasDefaultViewModelProviderFactory
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner

class App : Application(), ViewModelStoreOwner, HasDefaultViewModelProviderFactory {

    override fun onCreate() {
        super.onCreate()
    }

    private val mViewModelStore by lazy {
        ViewModelStore()
    }

    private val mViewModelFactory by lazy {
        ViewModelProvider.AndroidViewModelFactory(this)
    }

    override val defaultViewModelProviderFactory: ViewModelProvider.Factory
        get() = mViewModelFactory

    override val viewModelStore: ViewModelStore
        get() = mViewModelStore

    fun getAppViewModel() = ViewModelProvider(viewModelStore, defaultViewModelProviderFactory)[AppViewModel::class.java]
}